package com.fzu.ess.sys.service.Impl;

import com.fzu.ess.sys.dao.RoleDao;
import com.fzu.ess.sys.entity.Role;
import com.fzu.ess.sys.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ercha on 2015/10/21.
 */
@Service
public class RoleServiceImpl implements RoleService{

    @Autowired
    private RoleDao roleDao;

    @Override
    public String create(Role role) {
        try {
            return (String) roleDao.save(role);
        } catch(Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public boolean delete(Role role) {
//        roleDao.executeHql("delete from Role r where r.id = '" + id + "'");
        try {
            roleDao.delete(role);
            return true;
        } catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean update(Role role) {
        try {
            roleDao.update(role);
            return true;
        } catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public Role findById(String id) {
        return roleDao.get(Role.class, id);
    }

    @Override
    public List<Role> getAllRole() {
        return roleDao.find("from Role");
    }

}
